package com.huadi.firematerialident.controller;

import com.huadi.firematerialident.po.NormalUser;
import com.huadi.firematerialident.service.NormalUserServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;


import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/normalUserOps")
public class NormalUserController {

    @Autowired
    NormalUserServiceImpl normalUserService;
    @Autowired
    JdbcTemplate jdbcTemplate;


    @RequestMapping("/normalUserGetInfo")
    public String getInfo(Model model){
        List<Map<String,Object>> list = jdbcTemplate.queryForList("select * from normaluser where NUserID=?",normalUserService.getNUserID());
        model.addAttribute("info",list);
        return "MyInfo";
    }

    @RequestMapping("/normalUserUpdate")
    public String updateNormalUser(NormalUser normalUser,Model model){
        normalUserService.updateNormalUser(normalUser);
        List<Map<String,Object>> list = jdbcTemplate.queryForList("select * from normaluser where NUserID=?",normalUserService.getNUserID());
        model.addAttribute("info",list);
        return "MyInfo";
    }

}
